[id].vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <!-- 页面头部 -->
  3. <HomePageHead></HomePageHead>
  4. <!-- Banner1 -->
  5. <HomeBanner1></HomeBanner1>
  6. <!-- 面包屑导航 -->
  7. <div class="breadcrumb">
  8. <div class="inner">
  9. <span class="location">当前位置:</span>
  10. <el-breadcrumb :separator-icon="ArrowRight">
  11. <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
  12. <el-breadcrumb-item :to="{ path: `/newsList/${routLevelId}` }">{{ routLevelTitle }}</el-breadcrumb-item>
  13. <el-breadcrumb-item>{{ routeNewsTtitle }}</el-breadcrumb-item>
  14. </el-breadcrumb>
  15. </div>
  16. </div>
  17. <!-- 资讯列表 -->
  18. <div class="newsDetail">
  19. <div class="inner">
  20. <div class="innerLeft">
  21. <div class="LeftTop">
  22. <h1>{{ newsDetail.title }}</h1>
  23. <p>
  24. 来源: <span>{{ newsDetail.copyfrom }}</span>
  25. 作者: <span>{{ newsDetail.author }}</span>
  26. <!-- <span>{{ newsDetail.updated_at }}</span> -->
  27. <!-- 浏览量: <span>{{ newsDetail.hits }}</span> -->
  28. </p>
  29. <img :src="newsDetail.imgurl" alt="">
  30. </div>
  31. <div class="leftBottom" v-html="newsDetail.content"></div>
  32. <!-- 免责声明: -->
  33. <div class="disclaimer">
  34. <p>原文链接:http://baidu.com</p>
  35. <p>[免责声明]本文来源于网络转载,仅供学习交流使用,不构成商业目的。 版权归原作者所有,如涉及作品内容,版权和其他问题,请在30日与本网联系,我们将第一时间处理。</p>
  36. </div>
  37. </div>
  38. <div class="innerRight">
  39. <!-- 热点资讯1 -->
  40. <div class="hotList1">
  41. <DetailHotNews></DetailHotNews>
  42. </div>
  43. <!-- 热点资讯2 -->
  44. <div class="hotList2">
  45. <DetailHotNews2></DetailHotNews2>
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. <!-- 页面底部 -->
  51. <HomeFoot></HomeFoot>
  52. </template>
  53. <script setup>
  54. import { onMounted } from 'vue'
  55. import { ElBreadcrumb, ElBreadcrumbItem } from 'element-plus'
  56. import { ArrowRight } from '@element-plus/icons-vue'
  57. const nuxtApp = useNuxtApp();
  58. const axios = nuxtApp.$axios;
  59. //获得跳转过来的id
  60. const route = useRoute();
  61. const articleId = route.params.id; //获得该页面的id
  62. const listid = route.query.listId; //获得该页面的id
  63. const name = route.query.listName; //获得该页面的id
  64. // 定义响应式数据
  65. const seoData = ref({
  66. title: '三农资讯网',
  67. description: '默认描述',
  68. keywords: '默认关键词',
  69. image: 'https://example.com/default-image.jpg'
  70. });
  71. // 在 onMounted 钩子中获取数据
  72. onMounted(async () => {
  73. try {
  74. const response = await axios.get(`/web/selectWebsiteArticleInfo?articleid=${articleId}`);
  75. const data = response.data; // 假设接口返回的数据在 data 字段中
  76. // 更新 seoData
  77. seoData.value = {
  78. title: data.title,
  79. description: data.seo_description,
  80. keywords: data.keyword,
  81. image: data.introduce
  82. };
  83. } catch (error) {
  84. console.error('获取 SEO 数据失败:', error);
  85. // 设置默认值
  86. seoData.value = {
  87. title: '三农资讯网',
  88. description: '默认描述',
  89. keywords: '默认关键词',
  90. image: 'https://example.com/default-image.jpg'
  91. };
  92. }
  93. });
  94. // 监听 seoData 的变化,动态设置 SEO 字段
  95. watch(seoData, (newVal) => {
  96. if (newVal.title) { // 确保 title 有值
  97. useSeoMeta({
  98. title: newVal.title, // 使用动态值
  99. description: newVal.description,
  100. ogTitle: newVal.title,
  101. ogDescription: newVal.description,
  102. ogImage: newVal.image,
  103. twitterTitle: newVal.title,
  104. twitterDescription: newVal.description,
  105. twitterImage: newVal.image,
  106. keywords: newVal.keywords
  107. });
  108. }
  109. }, { immediate: true });
  110. const newsDetail = ref({})
  111. const routeNewsTtitle = ref("");
  112. //发布日期
  113. const time = ref("");
  114. //路径
  115. const routLevelTitle = ref("");
  116. const routLevelId = ref("");
  117. //获取详情
  118. const getNewsInfo = async () => {
  119. const response = await axios.get(`/web/selectWebsiteArticleInfo?articleid=${articleId}`);
  120. newsDetail.value = response.data;
  121. routLevelTitle.value = newsDetail.value.cat_name
  122. routLevelId.value = newsDetail.value.cat_id
  123. time.value = newsDetail.value.updated_at.split(' ')[0]
  124. if (newsDetail.value.title.length >= 30) {
  125. routeNewsTtitle.value = newsDetail.value.title.substr(0, 30) + "...";
  126. } else {
  127. routeNewsTtitle.value = newsDetail.value.title
  128. }
  129. }
  130. onMounted(() => {
  131. getNewsInfo()
  132. })
  133. </script>
  134. <style lang="less" scoped>
  135. //导航条
  136. .breadcrumb {
  137. width: 100%;
  138. height: 22px;
  139. margin-bottom: 30px;
  140. font-family: Microsoft YaHei, Microsoft YaHei;
  141. font-weight: 400;
  142. font-size: 20px;
  143. color: #666666;
  144. line-height: 23px;
  145. text-align: left;
  146. font-style: normal;
  147. text-transform: none;
  148. .el-breadcrumb::v-deep {
  149. display: inline-block;
  150. vertical-align: -4px;
  151. }
  152. /deep/.el-breadcrumb__inner a,
  153. /deep/.el-breadcrumb__inner.is-link {
  154. color: #666666;
  155. font-weight: 400;
  156. text-decoration: none;
  157. transition: var(--el-transition-color);
  158. }
  159. span {
  160. font-family: Microsoft YaHei, Microsoft YaHei;
  161. font-weight: 400;
  162. font-size: 20px;
  163. color: #666666;
  164. line-height: 23px;
  165. text-align: left;
  166. font-style: normal;
  167. text-transform: none;
  168. }
  169. span:hover {
  170. color: #666666;
  171. }
  172. .location {
  173. margin-right: 20px;
  174. width: 100px;
  175. height: 22px;
  176. font-family: Microsoft YaHei, Microsoft YaHei;
  177. font-weight: 400;
  178. font-size: 20px;
  179. color: #666666;
  180. line-height: 23px;
  181. text-align: left;
  182. font-style: normal;
  183. text-transform: none;
  184. }
  185. }
  186. // 资讯列表
  187. .newsDetail {
  188. width: 100%;
  189. //height: 1400px;
  190. margin-bottom: 70px;
  191. .inner {
  192. width: 1200px;
  193. //height: 1400px;
  194. overflow: hidden;
  195. font-size: 16px;
  196. .innerLeft {
  197. // height: 1400px;
  198. border-top: 1px solid #139602;
  199. .LeftTop {
  200. height: 522px;
  201. margin-top: 50px;
  202. >h1 {
  203. line-height: 40px;
  204. margin-bottom: 30px;
  205. font-family: Microsoft YaHei, Microsoft YaHei;
  206. font-weight: bold;
  207. font-size: 30px;
  208. color: #333333;
  209. }
  210. >p {
  211. height: 18px;
  212. line-height: 18px;
  213. font-family: Microsoft YaHei, Microsoft YaHei;
  214. font-weight: 400;
  215. font-size: 14px;
  216. color: #999999;
  217. span {
  218. margin-right: 40px;
  219. }
  220. }
  221. >img {
  222. width: 680px;
  223. height: 382px;
  224. padding: 50px 0px 60px 55px;
  225. }
  226. }
  227. .leftBottom {
  228. width: 790px;
  229. // height: 754px;
  230. margin-top: 76px;
  231. font-size: 20px;
  232. line-height: 38px;
  233. margin-bottom: 30px;
  234. // img{
  235. // width: 790px;
  236. // height: 382px;
  237. // }
  238. >h3,
  239. >p {
  240. text-indent: 2em;
  241. width: 790px;
  242. font-family: Microsoft YaHei, Microsoft YaHei;
  243. font-size: 20px;
  244. color: #333333;
  245. line-height: 38px;
  246. padding-bottom: 30px;
  247. }
  248. >h3 {
  249. font-weight: 600px;
  250. }
  251. >p {
  252. font-weight: 400;
  253. }
  254. }
  255. .disclaimer {
  256. border-top: 1px solid #e6e6e6;
  257. padding: 30px 0px;
  258. color: #999999 ;
  259. font-size: 20px;
  260. p{
  261. line-height: 30px;
  262. }
  263. // font-family: Microsoft YaHei, Microsoft YaHei;;
  264. }
  265. }
  266. .innerRight {
  267. width: 381px;
  268. // height: 605px;
  269. overflow: hidden;
  270. border-top: 1px solid #139602;
  271. .hotList1 {
  272. margin-bottom: 50px;
  273. }
  274. }
  275. }
  276. }
  277. </style>